package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * 利用反射机制调用Person类中所有得无参方法
 */
public class Test1 {
    public static void main(String[] args) throws Exception {
        Class cla = Class.forName("reflect.Person");
        Object obj = cla.newInstance();
        System.out.println(obj);
        Method[] methods = cla.getDeclaredMethods();
        for (Method method : methods){
            if (method.getParameterCount()==0
                    &&
               method.getModifiers()== Modifier.PUBLIC
            ) {
                method.invoke(obj);
            }
        }







    }
}
